package org.sn.jdish.spring.springboot.controller;

import java.util.concurrent.TimeUnit;

import org.sn.jdish.spring.springboot.client.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * springboot redisTemplate
 * 
 * @author snzigod@hotmail.com
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

	@Autowired
	private RedisClient<String> redisClient;

	@ResponseBody
	@RequestMapping("/sayHello")
	String home(String id) {
		String key = id;
		if (redisClient.hasKey(key)) {
			redisClient.delete(key);
		}
		redisClient.set(key, "hello, " + id + "!", 10, TimeUnit.SECONDS);
		return redisClient.get(key);
	}

}
